package com.ait.cms.controller;


import com.ait.cms.entity.CrmBanner;
import com.ait.cms.service.CrmBannerService;
import com.ait.commonutils.Msg;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-06-26
 */
@RestController
@RequestMapping("/cms/BannerAdmin")
public class BannerAdminController {

    @Autowired
    private CrmBannerService crmBannerService;




    @ApiOperation("获取所有Banner")
    @GetMapping("pageBanner")
    public Msg pageBanner(Integer page,Integer limit){
        Page<CrmBanner> crmBannerPage = new Page<CrmBanner>(page,limit);

        IPage<CrmBanner> page1 = crmBannerService.page(crmBannerPage, null);
        List<CrmBanner> records = page1.getRecords();

        if (records.size()>0)return Msg.success().data("total",records);
        return Msg.fail();
    }

    @ApiOperation(value = "获取Banner")
    @GetMapping("getBanner/{id}")
    public Msg get(@PathVariable String id) {
        CrmBanner banner = crmBannerService.getById(id);
        return Msg.success().data("item", banner);
    }


    @ApiOperation(value = "新增Banner")
    @PostMapping("saveBanner")
    public Msg save(@RequestBody CrmBanner banner) {
        crmBannerService.save(banner);
        return Msg.success();
    }


    @ApiOperation(value = "修改Banner")
    @PutMapping("updateBanner")
    public Msg updateById(@RequestBody CrmBanner banner) {
        crmBannerService.updateById(banner);
        return Msg.success();
    }


    @ApiOperation(value = "删除Banner")
    @DeleteMapping("removeBanner/{id}")
    public Msg remove(@PathVariable String id) {
        crmBannerService.removeById(id);
        return Msg.success();
    }

}

